package messages;

import java.io.Serializable;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * The Interface Convertible provides the abstraction to the serialization of the messages. To a message can
 * be sent and/or received in this application it's only needed that the class implements that interface and
 * correctly implements the convertToCanonic and convertFromCanonic methods. By implementing this interface
 * is still allowed to serialize the messages as objects.
 */
public interface Convertible extends Serializable {

	/**
	 * This abstract method defines the interface of the method convertToCanonic. This method should convert
	 * all of the class fields to DOM XML Elements using one Element per field. The root Element should have 
	 * the name of the class to be easy to address the right conversion method without no need of verification.
	 * 
	 * @param doc the Document to which the Element created has to be appended.
	 * 
	 * @return the Element created by converting the object to DOM XML.
	 */
	public Element convertToCanonic(Document doc);

	/**
	 * This abstract method defines the interface of the method convertFromCanonic. This method should convert
	 * the given Element to the fields of this class. If there has some elements that are not set the fields
	 * should be set to null.
	 * 
	 * @param el , the Element that we know to belong to the class that implements this method.
	 * 
	 * @return the Object converted from the given element.
	 */
	public Object convertFromCanonic(Element el);
}
